<?php
/**
 *银行管理
*/

namespace xhadmin\service\admin\record;

use xhadmin\CommonService;
use xhadmin\db\Bank;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

class BankService extends CommonService {


	/*
 	* @Description  会员管理列表数据
 	* @param (输入参数：)  {array}        where 查询条件
 	* @param (输入参数：)  {int}          limit 分页参数
 	* @param (输入参数：)  {String}       field 查询字段
 	* @param (输入参数：)  {String}       orderby 排序字段
 	* @return (返回参数：) {array}        分页数据集
 	*/
	public static function pageList($where=[],$limit,$field='*',$orderby=''){
		try{
			$list = Bank::loadList($where,$limit,$field,$orderby);
			$count = Bank::countList($where);
		}catch(\Exception $e){
			throw new \Exception($e->getMessage());
		}
		return ['list'=>$list,'count'=>$count];
	}


	/*
 	* @Description  添加
 	* @param (输入参数：)  {array}        data 原始数据
 	* @return (返回参数：) {bool}
 	*/
	public static function add($data){
		try{
			$data['create_time'] = $data['update_time'] =time();
			$res = Bank::createData($data);
		}catch(\Exception $e){
			throw new \Exception($e->getMessage());
		}
		return $res;
	}


	/*
 	* @Description  修改
 	* @param (输入参数：)  {array}        data 原始数据
 	* @return (返回参数：) {bool}
 	*/
	public static function update($data){
		try{
			$data['update_time'] = time();
            //p($data);exit;
			//数据验证
			/*$rule = [
				'mobile'=>['unique:member','regex'=>'/^1[345678]\d{9}$/'],
				'email'=>['regex'=>'/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/'],
			];
			$msg = [
				'mobile.unique'=>'手机号已经存在',
				'mobile.regex'=>'手机号格式错误',
				'email.regex'=>'邮箱格式错误',
			];*/
//            $rule = [
//                'id_card'=>['unique','regex'=>'/^\d{13}$/'],
//            ];
//            $msg = [
//                'id_card.unique'=>'客户已经存在',
//            ];
            //self::validate($rule,$data,$msg);
            //p($data);exit;
			$res = Bank::edit($data);
		}catch(\Exception $e){
            throw new \Exception($e->getMessage());
		}
		return $res;
	}

	public static function editWhere($where = [],$data) {
        try{
            $data['update_time'] = time();
            $res = Bank::editWhere($where,$data);
        }catch(\Exception $e){
            throw new \Exception($e->getMessage());
        }
        return $res;
    }


	/*
 	* @Description  删除
 	* @param (输入参数：)  {array}        where 删除条件
 	* @return (返回参数：) {bool}
 	*/
	public static function delete($where){
		try{
			$res = Bank::delete($where);
		}catch(\Exception $e){
			throw new \Exception($e->getMessage());
		}
		return $res;
	}



}

